
if exists (select 1 from sysobjects where name = 'set_personkuendigung' and type = 'P')
begin
   drop procedure set_personkuendigung
   print 'Procedure: set_personkuendigung deleted ...'
end
go

create procedure set_personkuendigung(
  @prsid       int   = 1,
  @bis         varchar(8)   = '20090101'
)
as
begin

   set nocount on
   
   update Arbeitspensum
      set Bis = convert(datetime, @bis, 112),
          Status = 2
    where PrsID = @prsid 
      --and Status = 1
      and Bis >= convert(datetime, @bis, 112)

   update PersonAnstellung
      set Bis = convert(datetime, @bis, 112)
   where PrsID = @prsid
     and Bis >= convert(datetime, @bis, 112)
   
   update PersonalAbteilung
   set Bis = convert(datetime, @bis, 112),
       Status = 2
   where PrsId = @prsid
     and Bis >= convert(datetime, @bis, 112)

end
go
print 'Procedure: set_personkuendigung done ...'
go
grant exec on set_personkuendigung to prsadmins with grant option
go
grant exec on set_personkuendigung to prsusers
go

